﻿using MessageQuque.Common.Base.Business;
using MessageQuque.Server.Enums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MessageQuque
{
    public class Receiver<T> : ReceiverBase, IReceiver
    {
        public void Dequeue()
        {
            string queueName = typeof(T).FullName;
            var applicantList = base.Dequeue<T>(queueName);

            if (applicantList[Status.All] == 0 && applicantList[Status.Success] == 0 && applicantList[Status.Failure] == 0)
            {
                return;
            }

            Console.WriteLine("队列：{0}\r\n已执行完成，本次共处理了 {1} 条数据\r\n成功 {2}，失败 {3}。\r\n时间：{4}\r\n", queueName,
                applicantList[Status.All], applicantList[Status.Success], applicantList[Status.Failure], DateTime.Now);
        }

        public void SetBusiness(IBusiness bll)
        {
            Business = bll;
        }
    }

    public class Receiver : ReceiverBase, IReceiver
    {
        const string DEFAULT_KEY = "MessageQuque.Quque.Default";
        public void Dequeue()
        {
            Console.WriteLine("开始处理队列", DEFAULT_KEY);

            var applicantList = base.Dequeue<string>(DEFAULT_KEY);

            Console.WriteLine("队列：{0} 已执行完成，本次共处理了 {1} 条数据\r\n成功 {2}，失败 {3}。\r\n时间：{4}\r\n", DEFAULT_KEY,
                applicantList[Status.All], applicantList[Status.Success], applicantList[Status.Failure], DateTime.Now);
        }

        public void SetBusiness(IBusiness bll)
        {
            Business = bll;
        }
    }
}
